home *** CD-ROM | disk | FTP | other *** search
- /*________________________________________________________________________________
- Debug.h: general purpose debugging code.
- ________________________________________________________________________________*/
-
- #pragma once
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- /*________________________________________________________________________________
- some compilers don't support #pragma mark, which allows nice markers in the
- source file routine name popup menu.
- ________________________________________________________________________________*/
- #ifdef __MWERKS__
- // CodeWarrior supports this...
- #define PRAGMA_MARK_SUPPORTED 1
- #endif
-
-
-
-
- /*________________________________________________________________________________
- utility macros
- ________________________________________________________________________________*/
- #define IsntNil( p ) ( (p) != nil )
- #define IsNil( p ) ( (p) == nil )
-
- #define IsntErr( e ) ( (e) == noErr )
- #define IsErr( e ) ( (e) != noErr )
-
-
-
-
-
- #if DEBUG // [
- /*________________________________________________________________________________
- OSErrString tables
- ________________________________________________________________________________*/
-
- // a single entry in an error table. An array of these constitutes a table.
- typedef struct DebugOSErrStringTableEntry
- {
- OSErr err;
- const char *cString; // a C string
- } DebugOSErrStringTableEntry;
-
- void DebugAddOSErrStringTable( const DebugOSErrStringTableEntry * entries, UInt16 numEntries);
-
- #endif // ]
-
-
-
-
- /*________________________________________________________________________________
- basic asserts and their variants...
- ________________________________________________________________________________*/
- #if DEBUG // [
-
- void DebugNumToString( long num, StringPtr string);
-
- void GetDebugNumString( ConstStr255Param msg, long num, StringPtr resultStr);
-
- #define DebugMsg(failStr) {DebugStr(failStr);}
- #define DebugMsgIf( cond, failStr) {if ( (cond) ) { DebugMsg(failStr);}}
- #define DebugNum( failStr, num ) { Str255 msg; GetDebugNumString( failStr, num, msg); DebugStr( msg ); }
-
- #define Assert(cond, failStr) DebugMsgIf( !(cond), failStr)
-
- #else // ] DEBUG [
-
- #define DebugMsg(failStr) {/* nothing */}
- #define DebugMsgIf( cond, failStr) {/* nothing */}
- #define DebugNum( msg, num ) {/* nothing */}
- #define Assert(cond, failStr) {/* nothing */}
-
- #endif // ] DEBUG
-
-
-
-
- /*________________________________________________________________________________
- more complex asserts
- ________________________________________________________________________________*/
- #if DEBUG // [
-
- void _AssertHandleIsValid(const void *theHandle, const char *cString, ConstStr255Param optionalMsg);
- void _AssertAddressIsValidAlign(const void *address, const char *cString, UInt32 align, ConstStr255Param optionalMsg);
- void AssertNoErr( OSErr err, ConstStr255Param optionalMsg);
-
- #define AssertHandleIsValid(h, msg) _AssertHandleIsValid( (h), #h, msg)
- #define AssertResourceIsValid(r, msg) _AssertHandleIsValid( (r), #r, msg)
- #define AssertAddressIsValidAlign(p, a, msg) _AssertAddressIsValidAlign( (p), #p, a, msg)
- #define AssertAddressIsValid(p, msg) AssertAddressIsValidAlign( p, 1, msg)
- #define AssertAddressIsValidAlign2( p, msg) AssertAddressIsValidAlign( p, 2, msg)
- #define AssertAddressIsValidAlign4( p, msg) AssertAddressIsValidAlign( p, 4, msg)
-
- #else // ] DEBUG [
-
- #define AssertHandleIsValid(h, msg) {/*nothing*/}
- #define AssertResourceIsValid(r, msg) {/*nothing*/}
- #define AssertAddressIsValid(p, msg) {/*nothing*/}
- #define AssertAddressIsValidAlign(p, a, msg) {/*nothing*/}
- #define AssertAddressIsValidAlign2( p, msg) {/*nothing*/}
- #define AssertAddressIsValidAlign4( p, msg) {/*nothing*/}
- #define AssertNoErr(err, msg) {/*nothing*/}
-
- #endif // DEBUG
-
-
-
-
-
- /*________________________________________________________________________________
- 'USE_DEBUG_TRAPS' controls whether debugging traps are used.
- It can be set before including this file. Otherwise, it defaults
- to the same status as DEBUG
- ________________________________________________________________________________*/
- #ifndef USE_DEBUG_TRAPS
- #define USE_DEBUG_TRAPS ( DEBUG )
- #endif
-
- #if USE_DEBUG_TRAPS
- #include "DebugTraps.h"
- #endif
-
-
-
-
- /*________________________________________________________________________________
- 'USE_DEBUG_LEAKS' controls whether leaks code compiles in.
- it can be set before #including this file. Otherwise, it defaults
- to the same status as USE_DEBUG_TRAPS.
- ________________________________________________________________________________*/
- #ifndef USE_DEBUG_LEAKS
- #define USE_DEBUG_LEAKS ( USE_DEBUG_TRAPS )
- #else
- // USE_DEBUG_LEAKS must be off if USE_DEBUG_TRAPS is off
- #if ! USE_DEBUG_TRAPS
- #undef USE_DEBUG_LEAKS
- #define USE_DEBUG_LEAKS 0
- #endif
- #endif
-
- #include "DebugLeaks.h"
-
-
-
- #ifdef __cplusplus
- }
- #endif
-
-
-
-
-